# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Newbyte <newbyte@postmarketos.org>
pkgname=gcr4
pkgver=4.3.0
pkgrel=1
pkgdesc="Library for bits of crypto UI and parsing"
url="https://wiki.gnome.org/Projects/CryptoGlue"
arch="all"
license="LGPL-2.0-or-later"
makedepends="
	glib-dev
	gobject-introspection-dev
	gtk-doc
	gtk4.0-dev
	libgcrypt-dev
	libsecret-dev
	libxslt
	meson
	openssh-client
	p11-kit-dev
	vala
	"
checkdepends="
	bash
	dbus
	xvfb-run
	"
subpackages="
	$pkgname-dev
	$pkgname-lang
	$pkgname-base
	gcr-ssh-agent:ssh
	"
source="https://download.gnome.org/sources/gcr/${pkgver%.*}/gcr-$pkgver.tar.xz
	gcr-ssh-agent-wrapper
	gcr-ssh-agent.desktop
	30-gcr-ssh-agent.sh"
builddir="$srcdir/gcr-$pkgver"
options="!check" # fix later after p11-kit fixes

build() {
	abuild-meson \
		-Db_lto=true \
		-Dgtk_doc=false \
		-Dgpg_path=/usr/bin/gpg2 \
		-Dsystemd=disabled \
		. output
	meson compile -C output
}

check() {
	XDG_RUNTIME_DIR="$(mktemp -d -p "$builddir")" \
	dbus-run-session -- \
		xvfb-run -a \
		meson test -t10 --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

base() {
	pkgdesc="$pkgdesc (base libraries)"
	depends=""

	amove usr/lib
}

ssh() {
	pkgdesc="$pkgdesc (ssh agent daemon)"
	depends="gcr4" # for gcr4-ssh-askpass

	amove usr/libexec/gcr-ssh-agent

	# Install wrapper used for gcr-ssh-agent autostart
	install -Dm755 "$srcdir"/gcr-ssh-agent-wrapper \
		"$subpkgdir"/usr/libexec/gcr-ssh-agent-wrapper
	install -Dm644 "$srcdir"/gcr-ssh-agent.desktop \
		"$subpkgdir"/etc/xdg/autostart/gcr-ssh-agent.desktop
	install -Dm644 "$srcdir"/30-gcr-ssh-agent.sh \
		"$subpkgdir"/etc/profile.d/30-gcr-ssh-agent.sh
}

sha512sums="
3f252de55e07d47a49c03b714e323ceb00d82e010fe1bb606073e3188bf8bef84359a322ed6fe843620fa5d108e825dd7e9a60136c8a0e802b8f2178aa87b164  gcr-4.3.0.tar.xz
d2b73edb885e7adcad7ec5117cbbb1d0a1b9139aed8c21923dcca22ca6af2b96d5e66ec0c966e1a219730e3fdc0d5866b40797377e9f0e394db8fdda16933625  gcr-ssh-agent-wrapper
90eefba939cc52b4251b4682dc8702d9a7f87ca2abd77b0caccd8fb0707692bc9fee9c23703388cb5336c1047731a4c6175423a03b05b1cf644c73040d0e244a  gcr-ssh-agent.desktop
f92d098db8146bdcacb7cc47b9ad5e9151cd1b26e786dfc164fe8c2941ded4f540e6458aedb0189ce52d49c46f7058bab86b9e02aae35962a487332503fb60ff  30-gcr-ssh-agent.sh
"
